package com.UI;

import java.util.List;
import com.Model.StudentDBModel;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class Grades extends ListActivity {
		
    private ListView lv1;
    String s;
    String courseNum;
    private CourseAdapter c_adapter;
    String[] sResult;

	 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.grades);
    	getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.grades_titlebar);
    	
    	((TextView)findViewById(R.id.titleGrades)).setText("Grade Progress");

    	
    	findViewById(R.id.back).setOnClickListener(new OnClickListener() {
    		public void onClick(View v) {
    			Grades.this.finish();

    		}
    	});
    	
    	StudentDBModel model = new StudentDBModel(this);
        
        lv1= getListView();
        lv1.setTextFilterEnabled(true);

        List<String> records = model.getGradeProgress();
        this.c_adapter = new CourseAdapter(this, R.layout.course_row, records);
        setListAdapter(this.c_adapter);
        
        registerForContextMenu(lv1);   
        
        lv1.setOnItemClickListener(new OnItemClickListener() {
        	public void onItemClick(AdapterView<?> a, View v, int position, long id) {

        		// isolate the course number and attach as extra
        		s = lv1.getItemAtPosition(position).toString();
        		sResult = s.split(":");
        		courseNum = sResult[0];
        		
            	Intent i = new Intent(Grades.this,ViewCourseActivity.class);
            	i.putExtra("CourseNo", courseNum);
            	startActivity(i);

        	}
        });
                                           
    }
	
}
